package com.yx.cloud.fragment;//package com.yx.b34.fragment;
//
//import android.app.Activity;
//import android.content.Intent;
//import android.graphics.Bitmap;
//import android.net.Uri;
//import android.os.Bundle;
//import android.util.Log;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//
//import androidx.fragment.app.Fragment;
//
//import com.google.gson.Gson;
//import com.yx.b34.AppContext;
//import com.yx.b34.BuildConfig;
//import com.yx.b34.R;
//import com.yx.b34.activity.AboutUsActivity;
//import com.yx.b34.activity.AccountManagActivity;
//import com.yx.b34.activity.HelpAndFeedbackActivity;
//import com.yx.b34.activity.MainActivity;
//import com.yx.b34.activity.MessageActivity;
//import com.yx.b34.activity.SwitchLanguageActivity;
//import com.yx.b34.constant.Constants;
//import com.yx.b34.databinding.LeftMenuBinding;
//import com.yx.b34.utils.AppUtil;
//import com.yx.b34.utils.Intent_utils;
//import com.yx.b34.utils.RomUtils;
//import com.yx.b34.utils.SharedPrefsUtil;
//import com.iot.base.bean.account.Account;
//import com.iot.common.utils.Event;
//
//import org.greenrobot.eventbus.EventBus;import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
//
//public class MenuLeftFragment extends Fragment implements View.OnClickListener {
//    private final static String TAG = "MenuLeftFragment";
//    public LeftMenuBinding binding;
//    MainActivity activity;
//    boolean appUpdate;
//    private View mView;
//    private Bitmap bitmap;
//    private String username, nickName, phone, email;
//    private int regFrom;
//    private Account account = null;
//
//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container,
//                             Bundle savedInstanceState) {
//        binding = LeftMenuBinding.inflate(getLayoutInflater());
//        return binding.getRoot();
//    }
//
//    @Override
//    public void onStart() {
//        super.onStart();
//        initData();
//        Log.d(TAG, "lf onStart=============== :");
//    }
//
//    private void initData() {
//        if (!EventBus.getDefault().isRegistered(this)) {//加上判断
//            EventBus.getDefault().register(this);
//        }
//        activity = (MainActivity) getActivity();
//        //获取系统状态栏高度
////        int statusBarHeight = StatusBarColorUtils.getStatusBarHeight(activity);
////        rl_title_top.setPadding(0, 130 + statusBarHeight, 0, 0);
////        Log.d(TAG, "lf 状态栏高度=============== :");
//        if (Constants.FLAVOR_INXNI.equals(BuildConfig.FLAVOR)) {
//            binding.rlMall.setVisibility(View.VISIBLE);
//        } else {
//            binding.rlMall.setVisibility(View.GONE);
//        }
//
//        try {
//            account = (Account) AppContext.getService().getUserInfo().get();
//        } catch (Throwable throwable) {
//            throwable.printStackTrace();
//        }
//        if (account != null) {
//            Log.i(TAG, account.getNickName() + "user is null : " + new Gson().toJson(account));
//            username = account.getAccount();
//            phone = account.getPhone();
//            email = account.getEmail();
//            regFrom = account.getRegFrom();
//            binding.tvLiftAccount.setText(username);
//            nickName = account.getNickName();
//            if (nickName == null || nickName.equals("")) {
//                binding.tvLiftNickName.setText(username);
//                Constants.nickName = username;
//            } else {
//                Constants.nickName = account.getNickName();
//                binding.tvLiftNickName.setText(account.getNickName());
//            }
//
//            String headPic = account.getHeadPicUrl();
//            Log.i(TAG, "user headPic : " + headPic);
//            if (headPic.equals("https://images.tuyacn.com/")) {
//                binding.headPortrait.setImageResource(R.mipmap.headportrait_icon);
//            } else {
//                //从服务器上加载头像
//                AppContext.getService().getUserHeadPicture(headPic);
//            }
//        }
//        appUpdate = SharedPrefsUtil.getValue(getActivity(), Constants.NOT_READ_TAG, Constants.KEY_APP_HAS_UPPER_VERSION, false);
//        if (appUpdate) {
//            binding.ivAppUpdateDot.setVisibility(View.VISIBLE);
//        } else {
//            binding.ivAppUpdateDot.setVisibility(View.GONE);
//        }
//
//        binding.rlAboutUs.setOnClickListener(this);
//        binding.rlHelpAndFeedback.setOnClickListener(this);
//        binding.rlSwitchLanguage.setOnClickListener(this);
//        binding.rlTitleTop.setOnClickListener(this);
//        binding.rlMessage.setOnClickListener(this);
//        binding.rlMall.setOnClickListener(this);
//
//    }
//
//
//    @Override
//    public void onClick(View v) {
//        if (RomUtils.isFastClick()) {
//            return;
//        }
//        int id = v.getId();
//        if (id == R.id.rl_message) {
////            activity.menu.toggle();
//            //消息
//            Intent_utils.enterIntentMenu(activity, MessageActivity.class);
//            //取消主界面注册,避免多次注册
//            EventBus.getDefault().unregister(activity);
//        } else if (id == R.id.rl_aboutUs) {
//            //关于
////                activity.menu.toggle();
//            Intent_utils.enterIntentMenu(activity, AboutUsActivity.class);
//            //取消主界面注册,避免多次注册
////                EventBus.getDefault().unregister(activity);
//        } else if (id == R.id.rl_helpAndFeedback) {
//            //帮助与反馈
////                activity.menu.toggle();
//            Intent_utils.enterIntentMenu(activity, HelpAndFeedbackActivity.class);
//            //取消主界面注册,避免多次注册
////                EventBus.getDefault().unregister(activity);
//        } else if (id == R.id.rl_title_top) {
////            activity.menu.toggle();
//            Intent intent = new Intent(activity, AccountManagActivity.class);
//            intent.putExtra("username", username);
//            intent.putExtra("nickName", Constants.nickName);
//            intent.putExtra("phone", phone);
//            intent.putExtra("email", email);
//            intent.putExtra("regFrom", regFrom);
//            startActivity(intent);
//            //取消主界面注册,避免多次注册
//            EventBus.getDefault().unregister(activity);
//        } else if (id == R.id.rl_switchLanguage) {
////            activity.menu.toggle();
//            //语言设置
//            Intent_utils.enterIntentMenu(activity, SwitchLanguageActivity.class);
//            //取消主界面注册,避免多次注册
////                EventBus.getDefault().unregister(activity);
//        } else if (id == R.id.rl_mall) {
//            //商城
//            //淘宝应用包名：com.taobao.taobao
//            //天猫应用包名：com.tmall.wireless
//            boolean taobaoPk = AppUtil.isPkgInstalled(activity, "com.taobao.taobao");
//            boolean tmallPk = AppUtil.isPkgInstalled(activity, "com.tmall.wireless");
//
//            Log.i(TAG, "商城     : " + taobaoPk + " " + tmallPk);
//
//            if (taobaoPk && tmallPk) {
//                gotoShop(activity, "tmall://page.tm/shop?shopId=468067551");
//            } else if (tmallPk) {
//                gotoShop(activity, "tmall://page.tm/shop?shopId=468067551");
//            } else if (taobaoPk) {
//                gotoShop(activity, "taobao://shop.m.taobao.com/shop/shop_index.htm?shop_id=468067551");
//            } else {
//                gotoShop(activity, "https://inxni.m.tmall.com");
//            }
//        }
//    }
//
//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public void onMessageEvent(Event event) {
//        switch (event.getType()) {
//            case Event.MESSAGE_TYPE_DOWNLOAD_HEADPICTRUE:
//                //头像
//                if (event.isResult()) {
//                    Bitmap bitmap = (Bitmap) event.getContent();
//
//                    if (bitmap != null) {
//                        Constants.mBitmap = bitmap;
//                        binding.headPortrait.setImageBitmap(bitmap);
//                    }
//                }
//                break;
//            case Event.MESSAGE_TYPE_HAS_NEW_MESSAGE:
//                //是否有新消息
//                if (event.isResult()) {
//                    boolean hasNew = (boolean) event.getContent();
//                    if (hasNew) {
//                        activity.binding.ivLeftMenuRedDot.setVisibility(View.VISIBLE);
//                        if (binding.ivLeftMenuMesRedDot != null) {
//                            binding.ivLeftMenuMesRedDot.setVisibility(View.VISIBLE);
//                        }
//                    } else {
//                        activity.binding.ivLeftMenuRedDot.setVisibility(View.GONE);
//                        if (binding.ivLeftMenuMesRedDot != null) {
//                            binding.ivLeftMenuMesRedDot.setVisibility(View.GONE);
//                        }
//                    }
//                }
//                break;
//        }
//    }
//
//    /**
//     * 跳转至商铺
//     *
//     * @param activity Activity
//     * @param url      商铺地址
//     */
//    public void gotoShop(Activity activity, String url) {
//        try {
//            Intent intent = new Intent();
//            intent.setAction("android.intent.action.VIEW");
//            intent.setData(Uri.parse(url));
//            activity.startActivity(intent);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//    @Override
//    public void onDestroyView() {
//        super.onDestroyView();
//    }
//
//}
